package com.simple.datax.conn;

import com.simple.datax.conn.impl.ConnectorFactory;
import com.simple.datax.core.model.connpara.CommonConnPara;


/** 
 * @Title: ConnectorPool.java 
 * @Package com.simple.datax.api 
 * @Description: This interface defines the interface about 
 * the connector pool for sending/receiving messages
 * @author Joe Jin 
 * @date 2012-12-25 
 * @version V1.0 
 */
public abstract class ConnectorPool {
	
	public final static String EXTEND_CHAR = ".";
	
	/**
	 * Generate key for getting connector
	 * @param connType
	 * @param connPara
	 * @return
	 */
	public static String getConnKey(String connType, String connPara) {
		if (connType == null) {
			return null;
		}
		int pos = -1;
		if ((pos=connType.indexOf(EXTEND_CHAR))>=0) {
			connType = connType.substring(0, pos);
		}
		String connKey = connType.toUpperCase() + ConnectorFactory.KEY_SPLITTER + connPara;
		return connKey;
	}
	
	/**
	 * borrow connector from pool
	 * @param connPara
	 * @return connector.
	 */
	abstract public BaseConnector borrowObject(CommonConnPara connPara);
	
//	/**
//	 * return connector to pool
//	 * @param connType
//	 * @param connPara
//	 * @param connector
//	 */
//	public void returnObject(String connType, String connPara, BaseConnector connector);
	
	/**
	 * return connector to pool
	 * @param connType
	 * @param connPara
	 * @param connector
	 */
	public abstract void returnObject(BaseConnector connector);
}
